package day17.myRelect3;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class RelectDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        ClassLoader classLoader = ClassLoader.getSystemClassLoader();
        InputStream is = classLoader.getResourceAsStream("prop1.properties");
        Properties prop1 = new Properties();
        prop1.load(is);
        // System.out.println(prop1);
        is.close();
        Class clazz = Class.forName("day17.myRelect3.Person");
        Constructor constructor = clazz.getConstructor();
        constructor.setAccessible(true);
        Person p = (Person) constructor.newInstance();//初始化
        Method m = clazz.getMethod("setName", String.class);
        m.invoke(p, "lihua");
        Field f = clazz.getDeclaredField("age");
        f.setAccessible(true);
        f.setInt(p, 23);
        System.out.println(p);


        // System.out.println(constructor);

    }
}
